package com.weds.frame.auth.service;

import com.weds.frame.auth.entity.ScBusinessOptApiCache;
import com.weds.frame.auth.entity.ScOptLog;
import com.weds.frame.auth.mapper.ScBusinessOptAuthMapper;
import com.weds.frame.auth.mapper.ScOptLogAuthMapper;
import com.weds.frame.core.util.JsonUtil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.HashMap;
import java.util.Map;

/**
 * Description:
 * Author: LiuWenQing
 * Datetime: 2023/4/4 16:48
 */
@Service
public class CommOptLogAuthService {

    @Autowired
    private ScOptLogAuthMapper scOptLogAuthMapper;
    @Autowired
    private ScBusinessOptAuthMapper scBusinessOptAuthMapper;

    public void sysLogInsert(ScOptLog o) {
        ScBusinessOptApiCache scBusinessOptApiCache = scBusinessOptAuthMapper.selectByOptApi(o.getOptApi());
        if (scBusinessOptApiCache == null)
            return;
        o.setOptName(scBusinessOptApiCache.getOptName()); //操作名称
        o.setOptNo(scBusinessOptApiCache.getOptNo()); //操作编号
        o.setOptTypeId(scBusinessOptApiCache.getOptTypeId()); //操作类别

        Map<String, String> m = o.getParamsUrl() == null ? new HashMap<>() : JsonUtil.paramToMap(o.getParamsUrl());
        o.setCtRm(m.containsKey("rm") ? m.get("rm") : "");
        o.setCtCal(m.containsKey("cal") ? m.get("cal") : "");
        if ("POST".equals(o.getRequestMethod())) {
        } else if ("GET".equals(o.getRequestMethod())) {
            o.setParamsBody(null);
        }
        scOptLogAuthMapper.insert(o);
    }
}
